/*
    XTU OJ: 1390
    by: fifth_light
*/

#include <stdio.h>
#include <string.h>
#include <assert.h>

int buffer = '\0';

void reset_array(int arr[26]) {
    for (int i = 0; i < 26; i++) {
        arr[i] = 0;
    }
}

int output_array(int arr[26]) {
    int flag = 0;
    for (int i = 0; i < 26; i++) {
        if (arr[i] != 0) {
            flag = 1;
            printf("%c : %d\n", 'a' + i, arr[i]);
        }
    }
    return flag;
}

int read_char() {
    if (buffer == '\0') {
        return buffer = getchar();
    } else {
        return buffer;
    }
}

void consume_buffer() {
    buffer = '\0';
}

int read_int() {
    int result = 0;
    while (1) {
        int c = read_char();
        if (c < '0' || c > '9') {
            break;
        }
        result *= 10;
        result += c - '0';
        consume_buffer();
    }
    return result;
}

void append_letters(int dest[26], int src[26], int cnt) {
    for (int i = 0; i < 26; i++) {
        dest[i] += src[i] * cnt;
    }
}

typedef struct {
    int data[26];
} letters_array;

letters_array read_in(int outer) {
    // 0: 还没碰到括号
    // 1: 读取数字
    int state = 0;
    int cnt = outer ? 1 : 0;
    int last_letter = 0;
    letters_array array;
    reset_array(array.data);
    while(1) {
        int c = read_char();
        if (outer == 0 && c == ')') {
            state = 1;
            consume_buffer();
            continue;
        }
        if (c == '(') {
            // go deep.
            consume_buffer();
            letters_array array_deep = read_in(0);
            append_letters(array.data, array_deep.data, 1);
            continue;
        }
        if (state == 0) {
            if (c >= 'a' && c <= 'z') {
                array.data[c - 'a']++;
                last_letter = c;
                consume_buffer();
            } else if (c >= '0' && c <= '9') {
                int lcnt = read_int(0);
                array.data[last_letter - 'a'] += lcnt - 1;
                continue;
            } else {
                break;
            }
        } else if (state == 1) {
            cnt = read_int();
            break;
        }
    }
    if (cnt != 1) {
        append_letters(array.data, array.data, cnt - 1);
    }
    if (!outer) {
        // BREAKPOINT BELOW
        assert(cnt != 0);
        assert(state == 1);
    }
    return array;
}

int main(void) {
    while (1) {
        letters_array array = read_in(1);
        if (output_array(array.data)) {
            putchar('\n');
        }
        reset_array(array.data);
        if (buffer == -1) {
            break;
        }
        consume_buffer();
    }
    return 0;
}
